package com.briup.facade.web.controller;

import com.briup.common.util.PageResult;
import com.briup.common.web.Message;
import com.briup.common.web.MessageUtil;
import com.briup.dataset.entity.DataSet;
import com.briup.dataset.entity.extend.DataSetEx;
import com.briup.dataset.service.IDatasetService;
import com.briup.logging.annotation.LoggingAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@LoggingAccess("数据集模块")
@RestController
@Api(tags = "数据集模块")
public class DatasetController {

    @Autowired
    private IDatasetService datasetService;

    @LoggingAccess("创建数据集")
    @ApiOperation(value="创建数据集",notes = "dataset_ratio为预留字段,参数含义可查看model")
    @PostMapping(value ="/dataset/",consumes = "application/json")
    public Message insertDataset(@RequestBody DataSet dataset){
        datasetService.insertDataset(dataset);
        return MessageUtil.success();
    }

    @LoggingAccess("条件查询数据集")
    @ApiOperation(value="条件查询数据集",notes = "参数形式为查询字符串,其中名称和类型是条件搜索")
    @GetMapping(value ="/dataset/findAll")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "datasetName",value="数据集名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "datasetType",value="数据集类型",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name="pageNum",value = "分页当前页",paramType = "query",dataType = "int",required = false),
            @ApiImplicitParam(name="pageSize",value = "分页大小",paramType = "query",dataType = "int",required = false),
    })
    public Message findAll(@RequestParam(name="datasetName",required = false) String datasetName,
                                 @RequestParam(name="datasetType",required = false) String datasetType,
                                 @RequestParam("pageNum") int pageNum,
                                 @RequestParam("pageSize") int pageSize){
        PageResult<DataSetEx> pageResult = datasetService.selectDataSetExListByCon(datasetType, datasetName, pageNum, pageSize);

        return MessageUtil.success(pageResult);
    }

    @LoggingAccess("根据id查看数据集详情")
    @ApiOperation(value="根据id查看数据集详情",notes = "参数形式为restful模板")
    @GetMapping(value ="/dataset/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "数据集id",paramType = "path",dataType = "int",required = true)
    })
    public Message selectDataSetExById(@PathVariable("id") Integer id){
        DataSetEx dataSetEx = datasetService.selectDataSetExById(id);
        return MessageUtil.success(dataSetEx);
    }


    @LoggingAccess("批量删除数据集")
    @ApiOperation(value="批量删除数据集",notes = "参数形式为restful模板")
    @DeleteMapping(value = "/dataset")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "数据集id集合",paramType = "query",dataType = "int",required = true,allowMultiple = true)
    })
    public Message deleteDataset(@RequestParam("ids") List<Integer> ids){
        // 事实上只要改变数据集状态即可
        datasetService.updateDatasetStatus(ids);
        return MessageUtil.success();
    }



}
